module common.systemmsg;

import mirgame, mirshare;

import share.container;

import allegro5.allegro;
import allegro5.allegro_primitives;
import allegro5.allegro_image;
import allegro5.allegro_font;


public final class SystemMessage
{
    private enum _MAX_SYSMSG = 10;

    private int m_wCurrDelay;
	private Vector!string m_stSysMsg;
	
	
    public this()
    {
        m_stSysMsg = m_stSysMsg.init;
        m_wCurrDelay = 0;
    }

    public void reset()
    {
        m_stSysMsg.clear;
		m_wCurrDelay = 0;
    }

    public void addMessage(string str)
    {
        m_stSysMsg.deleteRange(0, _MAX_SYSMSG);

		m_stSysMsg.add(str);
		m_wCurrDelay = 0;
    }

    public void update(int nLoopTime)
    {
        m_wCurrDelay += nLoopTime;
		
		ushort dwDelay = 3000;
		
        if ( m_stSysMsg.count > 5 )
			dwDelay = 1000;

		if ( m_wCurrDelay > dwDelay )
		{
			if ( m_stSysMsg.count > 0 )
				m_stSysMsg.deleteAt(0);

			m_wCurrDelay = 0;
		}
    }

    public void showMessage(float x, float y)
    {
		const fcolor = al_map_rgba(100, 200, 100, 255);
		const bcolor = al_map_rgba(10, 10, 10, 255);
		
        /*const int posX = 30, posY = 40;

        if (MsgList.Count > 0)
        {
            var graphics = (Graphics)Game.Services.GetService(typeof(Graphics));
            graphics.GetSpriteBatch.Begin();
            for (int i = 0; i < MsgList.Count; i++)
            {
                string msg = MsgList[i];
                if (string.IsNullOrEmpty(msg)) continue;

                graphics.DrawShadowText(msg, posX, posY + i * 15, new Color(10, 10, 10), new Color(100, 200, 100));
            }
            graphics.GetSpriteBatch.End();
        }

        base.Draw(gameTime);*/
		
		for ( int nCnt = 0; nCnt < m_stSysMsg.count; nCnt++ )
		{
			immutable message = m_stSysMsg[nCnt];

			if ( message.length > 0 )
			{
				MyPen.drawShadowText(x, y + nCnt * 15, fcolor, bcolor, message);
			}
		}
    }
}